// TOWN SCRIPT
//    Town 3: Corinth

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

// flags:
// 3, 0 = entry message flag
// 3, 1 = training on (true)/off (false)
// 3, 2 = classroom msg
// 3, 3 = shop message (guards place)
// 3, 4 = guards room msg
// 3, 5 = Paul conversation flag
// 3, 6 = got skill flag

begintownscript;

variables;

short choice, i, al, il;

body;

beginstate INIT_STATE;
	turn_off_training(TRUE);
	set_crime_tolerance(3);

	set_name(6, "Paul");
	set_char_dialogue_pic(6, 540, 0);
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
	if (get_flag(3, 0) == FALSE) {
		set_flag(3, 0, TRUE);
		reset_dialog();
		add_dialog_str(0, "The small town of Corinth depended on the farms surrounding it.", 0);
		add_dialog_str(1, "With farming slowed and little protection for the town, most of the citizens have left.", 0);
		add_dialog_str(2, "The Wilderness training academy is about the only place that is still operating.", 0);
		add_dialog_str(3, "The instructor and a few guards are all that are left in town.", 0);
		add_dialog_choice(0, "Ok");
		choice = run_dialog(TRUE);
	}
break;

beginstate 10;
	run_scenario_script(12);
break;

beginstate 11;
	if (get_flag(3, 1) == FALSE) {
		set_flag(3, 1, TRUE);
		turn_off_training(FALSE);
	}
break;

beginstate 12;
	if (get_flag(3, 1) > 0) {
		set_flag(3, 1, FALSE);
		turn_off_training(TRUE);
	}
break;

beginstate 13;
	if (get_flag(3, 2) == FALSE) {
		set_flag(3, 2, TRUE);
		message_dialog("This is a classroom to learn subjects other than combat.", "It does not look well used.");
	}
break;

beginstate 14;
	run_scenario_script(13);
break;

beginstate 15;
	reset_dialog();
	add_dialog_str(0, "The books in these shelves are mainly history books.", 0);
	add_dialog_str(1, "One about Corinth catches your eye.", 0);
	add_dialog_str(2, "The chapter that the book falls open to is about Lagoth Zanta and his band of followers.", 0);
	add_dialog_str(3, "It appears a few of them were destroyed on a ledge overlooking Corinth.", 0);
	add_dialog_str(4, "There appears to be a lightly drawn map in the margin that shows where the crevasse is that leads to the ledge.", 0);
	add_dialog_str(5, "No one has been up there since that time according to some notes also drawn in the margin.", 0);
	add_dialog_str(6, "It appears as if the people of Corinth were serious about leaving the followers to rot.", 0);
	add_dialog_choice(0, "Ok");
	choice = run_dialog(TRUE);
	set_flag(51, 1, TRUE);
break;

beginstate 16;
	if (get_flag(3, 3) == FALSE) {
		set_flag(3, 3, TRUE);
		message_dialog("The shop looks abandoned, a good while ago.  At least it is in habitable condition.",
			"It does look as if the room to the west is being used.");
	}
break;

beginstate 17;
	if (get_flag(3, 4) == FALSE) {
		set_flag(3, 4, TRUE);
		message_dialog("The room looks well lived in.", "The guards must stay here when not on duty.");
	}
break;

beginstate 18;
	if (get_flag(3, 6) == FALSE) {
		reset_dialog();
		add_dialog_str(0, "You find a book entitled 'Jack of all trades' in the desk.", 0);
		add_dialog_choice(0, "Read it");
		add_dialog_choice(1, "Put it back");
		choice = run_dialog(FALSE);
		if (choice == 1) {
			al = 7 * party_size();
			il = 10 * party_size();
			if ((get_skill_total(13) >= al) || (get_skill_total(2) >= il)) { // arcane lore or intelligence
				set_flag(3, 6, TRUE);
				message_dialog("The book is filled with facts and figures that increase your all-around skill.",
					"After you finish learning from it, it vanishes in a puff of smoke.");
				i = 0;
				while (i < 4) {
					if (char_ok(i) == TRUE) {
						change_pc_skill_pts(i, 10);
					}
					i = i + 1;
				}
			}
			else {
				message_dialog("The book puzzles you with facts and figures that just don't make sense.",
					"Even though some of the pictures are pretty, you put the book back into the desk.");
			}
		}
	}
	else {
		message_dialog("The desk contains nothing else.", "");
	}
break;
